package com.zn.net
{
    import com.zn.log.Log;

    import flash.net.getClassByAlias;
    import flash.utils.getQualifiedClassName;

    /**
     *xml编码
     * @author zn
     *
     */
    public class XMLEncoding
    {
        public function XMLEncoding()
        {
        }

        /**
         *解码
         * @param xml
         * @return
         *
         */
        public static function decode(xml:XML, info:*):void
        {
            var clientClassName:String = getQualifiedClassName(info);
            var propertyName:String;

            try
            {
                //把XML属性赋值给类
                for each (var propertyXML:XML in xml.children())
                {
                    propertyName = propertyXML.localName();
                    if (info.hasOwnProperty(propertyName))
                    {
                        info[propertyName] = propertyXML.toString();
                    }
                    else
                    {
                        Log.debug(XMLEncoding, "decode", clientClassName + "无:" + propertyName + "属性");
                    }
                }
            }
            catch (error:ReferenceError)
            {
                return Log.error(XMLEncoding, "decode", error.message);
            }
        }
    }
}